﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;


namespace QuanLyDuocPham.View.QuanLyHeThong.DanhMuc
{
    /// <summary>
    /// Interaction logic for DONTHUOC_Add_View.xaml
    /// </summary>
    public partial class DONTHUOC_Add_View : Window
    {
        public DONTHUOC_Add_View()
        {
            InitializeComponent();
        }
        string ma_dt;
        public string _ma_dt
        {
            set
            {
                ma_dt = value;
            }
        }
        public delegate void added();
        public added done;
        DONTHUOC_Control dtctrl = new DONTHUOC_Control();
        BACSI_Control bsctrl = new BACSI_Control();
        NHOMBENH_Control nhdpctrl = new NHOMBENH_Control();
        DUOCPHAM_Control dpctrl = new DUOCPHAM_Control();
        DONTHUOC_CT_Control dtctctrl = new DONTHUOC_CT_Control();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ma_dt=dtctrl.loadID_moi();
            bsctrl.loadComboBox(cmbBacSi);
            nhdpctrl.loadComboBox(cmbNhom);
            dpctrl.loadData(listDP);
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            dtctrl.addData(ma_dt, cmbBacSi, cmbNhom, txtTenToa, txtDien_Giai);
            dtctctrl.addData(listDPinToa, ma_dt);
            ma_dt=dtctrl.loadID_moi();
            txtDien_Giai.Clear();
            txtSearch.Clear();
            txtTenToa.Clear();
            cmbBacSi.SelectedItem = null;
            cmbNhom.SelectedItem = null;
            listDPinToa.Items.Clear();
            listDP.SelectedItem = null;
            if (done != null)
            {
                done();
            }
        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (listDP.SelectedItem == null)
                MessageBox.Show("Bạn chưa chọn dược phẩm nào để thêm vào danh sách!");
            else
            {
                var sl = (DUOCPHAM_GetByTenDuocPhamResult)listDP.SelectedItem;
                listDPinToa.Items.Add(sl);
                listDP.Items.Remove(listDP.SelectedItem);
            }


        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (listDPinToa.SelectedItem == null)
                MessageBox.Show("Bạn chưa chọn dược phẩm nào để xóa khỏi danh sách!");
            else
            {
                listDPinToa.Items.Remove(listDPinToa.SelectedItem);
                //DUOCPHAM_GetByTenDuocPhamResult sl = new DUOCPHAM_GetByTenDuocPhamResult();
                
                //sl.MA_DUOCPHAM = ((DUOCPHAM_GetByTenDuocPhamResult)(listDPinToa.SelectedItem)).MA_DUOCPHAM;
                //sl.TEN_DUOCPHAM = ((DUOCPHAM_GetByTenDuocPhamResult)(listDPinToa.SelectedItem)).TEN_DUOCPHAM;
                var sl = (DUOCPHAM_GetByTenDuocPhamResult)listDPinToa.SelectedItem;
                listDP.Items.Add(sl);
                
            }
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            
        }

        private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            dpctrl.findData(txtSearch, listDP);
        }

        private void cmbBacSi_KeyDown(object sender, KeyEventArgs e)
        {
            cmbBacSi.IsDropDownOpen = true;
        }

        private void cmbNhom_KeyDown(object sender, KeyEventArgs e)
        {
            cmbNhom.IsDropDownOpen = true;
        }
    }
}
